package com.beyondcreative.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.beyondcreative.stylebean.ContentActivity;
import com.beyondcreative.stylebean.R;

public class BeanHatchFragment extends Fragment {
	private static final String KEY_CONTENT = "TestFragment:Content";

	public static BeanHatchFragment newInstance(String content) {
		BeanHatchFragment fragment = new BeanHatchFragment();
		/*
		 * StringBuilder builder = new StringBuilder(); for (int i = 0; i < 20;
		 * i++) { builder.append(content).append(" "); }
		 * builder.deleteCharAt(builder.length() - 1);
		 * fragment.setmContent(builder.toString());
		 */
		return fragment;
	}

	public void setmContent(String mContent) {
		this.mContent = mContent;
	}

	private String mContent = "???";
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		/*FragmentManager fm = getFragmentManager();
		Fragment frag = fm.findFragmentById(R.id.fragment1);*/
		
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		/*
		 * if ((savedInstanceState != null) &&
		 * savedInstanceState.containsKey(KEY_CONTENT)) { mContent =
		 * savedInstanceState.getString(KEY_CONTENT); }
		 */
		// FragmentManager fm = getFragmentManager();
		// Fragment frag = fm.findFragmentById(R.id.fragment1);
		/*
		 * FragmentTransaction ft = fm.beginTransaction(); ft.show(frag);
		 * ft.commit();
		 */

	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		FrameLayout layout = (FrameLayout) inflater.inflate(
				R.layout.hatch_layout, container, false);
		FrameLayout fragment_layout = (FrameLayout) layout.findViewById(R.id.for_fragment_layout);
		if(savedInstanceState==null){
			Fragment newFragment = new NoticeFragment();
	        FragmentTransaction ft = getFragmentManager().beginTransaction();
	        ft.add(R.id.for_fragment_layout, newFragment).commit();
	        ft.hide(newFragment);
	        ft.show(newFragment);
		}
		return layout;
	}

	@Override
	public void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		// outState.putString(KEY_CONTENT, mContent);
	}

	public static class NoticeFragment extends Fragment {
		
		@Override
		public void onCreate(Bundle savedInstanceState) {
			super.onCreate(savedInstanceState);
			setRetainInstance(true);
			
		}

		@Override
		public View onCreateView(LayoutInflater inflater, ViewGroup container,
				Bundle savedInstanceState) {
			TextView tv = new TextView(getActivity());
			tv.setTextSize(48.0f);
			tv.setText("Go to Content");
			tv.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					 Intent intent = new Intent(getActivity(), ContentActivity.class);
					 startActivity(intent);
				}
			});
			//tv.setVisibility(View.GONE);
			return tv;
		}

		@Override
		public void onSaveInstanceState(Bundle outState) {
			super.onSaveInstanceState(outState);

			// Remember the current text, to restore if we later restart.
			// outState.putCharSequence("text", mTextView.getText());
		}

	}

}
